package com.tec.security.controller;

import com.tec.security.mapper.ViewsIPMapper;
import com.tec.security.mapper.ViewsMapper;
import com.tec.security.utils.other.UPResult;
import com.tec.security.utils.response.Result;
import io.swagger.annotations.Api;
import com.tec.security.service.ViewsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@Api(tags = "后台首页数据")
@RequestMapping("/IndexData")
public class IndexController {
    private final ViewsService viewsService;
    private final ViewsIPMapper viewsIPMapper;
    private final ViewsMapper viewsMapper;
    @Autowired
    public IndexController(ViewsService viewsService, ViewsIPMapper viewsIPMapper, ViewsMapper viewsMapper) {
        this.viewsService = viewsService;
        this.viewsIPMapper = viewsIPMapper;
        this.viewsMapper = viewsMapper;
    }

    /**
     * @description 最近7日uv,pv访问量接口
     * @author 陆林
     * @date 2023-11-9
     * @update 2023-11-30
     */
    @ApiOperation(value = "最近7日uv,pv访问量")
    @PostMapping("/PVUVList")
    public Result list(){
        Map<String,Object> result=new HashMap<>();
        List<UPResult> uvResultList=viewsMapper.UVList();
        result.put("uvList",uvResultList);
        List<UPResult> pvResultList=viewsIPMapper.PVList();
        result.put("pvList",pvResultList);
        return Result.success("请求成功",result);
    }

    /**
     * @description 数据统计
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "数据统计")
    @PostMapping("/allData")
    public Result allData(){
       return viewsService.allData();
    }
}
